﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StoryTeller.Repository;
using StoryTeller.Domain;
using System.Collections.Generic;
using System.Linq;

namespace StoryTeller.UnitTest.Repository
{
    [TestClass]
    public class StoryRepositoryUnitTest
    {
        public StoryRepository repository { get { return new StoryRepository(); } }

        public Story story
        {
            get
            {
                return new Story()
                {
                    IsPublic = true,
                    Title = "Story test001...",
                    Category = ECategory.adventure,
                    Description = "Story description",
                };
            }
        }

        [TestMethod]
        public void Insert()
        {
            repository.Insert(story);
        }

        [TestMethod]
        public void Update()
        {
            Story s = repository.Select().Last();
            s.Title += " = updated" + DateTime.Now.ToShortDateString();

            repository.Update(s);
        }

        [TestMethod]
        public void Delete()
        {
            Story s = repository.Select().Last();

            repository.Delete(s.Id);
        }

        [TestMethod]
        public void Select()
        {
            ICollection<Story> coll = repository.Select();

            Assert.IsNotNull(coll);
        }

        [TestMethod]
        public void SelectById()
        {
            Story s = repository.Select().Last();

            repository.Delete(s.Id);

            Assert.IsNotNull(s);
        }
    }
}
